using Common.Commands.FolderCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class FolderProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddFolder()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Accounting,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);

            var command = new AddFolder
            {
                Id = GuidComb.New(),
                Name = "Insurance Case",
                Tags = "Insurance, Helath",
                ReferenceId = account.Id,
                ReferenceName = account.Name,
                EntityType = EntityType.Account,
                Description = "Apollo Hospital Helth Case",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<FolderView>>();

            var folderView = repo.GetById(command.Id);

            Assert.AreEqual(folderView.Name, command.Name);
            Assert.AreEqual(folderView.Tags, command.Tags);
        }

        [Test]
        public void ShouldDeleteFolder()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Energy,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);
            var folder = new Folder
            {
                Id = GuidComb.New(),
                Name = "NewCase",
                Tags = "Insurance, Health",
                ReferenceId = account.Id,
                ReferenceName = account.Name,
                EntityType = EntityType.Account,
                Description = "Apollo Hospital Helth Case",
                ImageData = ImageUtility.NoImageData
            };
            Persist(folder);

            var command = new DeleteFolder(folder.Id);

            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<FolderView>>();
            var folderView = repo.GetById(command.Id);

            Assert.IsNull(folderView);
        }

        [Test]
        public void ShouldUpdateFolder()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Airline,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);
            var folder = new Folder
            {
                Id = GuidComb.New(),
                Name = "NewCase",
                Tags = "Insurance, Health",
                ReferenceId = account.Id,
                ReferenceName = account.Name,
                EntityType = EntityType.Account,
                Description = "Apollo Hospital Helth Case",
                ImageData = ImageUtility.NoImageData
            };
            Persist(folder);

            var command = new UpdateFolder
            {
                Id = folder.Id,
                Tags = "Insurance",
                Name = "NewCase",
                ReferenceId = account.Id,
                ReferenceName = account.Name,
                EntityType = EntityType.Account,
                Description = "Hospital Helth",
                ImageData = ImageUtility.NoImageData
            };

            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<FolderView>>();
            var folderView = repo.GetById(command.Id);

            Assert.AreEqual(folderView.Id, folder.Id);
            Assert.AreNotEqual(folderView.Description, folder.Description);
        }
    }
}